﻿using LoveEatRabbit.API.Read.Applications.Commands.Permissions;
using LoveEatRabbit.Domain.RBAC;
using LoveEatRabbit.ErrorCode;
using LoveEatRabbit.Infrastructure.Interfaces;
using MediatR;

namespace LoveEatRabbit.API.Read.Applications.CommandHandlers.Permission
{
    public class PerSelectQueryCommandHandler : IRequestHandler<PerSelectQueryCommand, APIResult<List<PermissionModel>>>
    {
        private readonly IBaseRespository<PermissionModel> perRep;

        public PerSelectQueryCommandHandler(IBaseRespository<PermissionModel> perRep)
        {
            this.perRep = perRep;
        }

        public Task<APIResult<List<PermissionModel>>> Handle(PerSelectQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<PermissionModel>> result=new APIResult<List<PermissionModel>>();
            result.Code=APIResultCode.查询成功;
            result.Message=APIResultCode.查询成功.ToString();

            var res=perRep.GetAll().ToList();
            result.Data=res;


            return Task.FromResult(result);
        }
    }
}
